package com.snake.springboot.custom.service.impl.base;

import com.snake.springboot.custom.api.model.base.CustRoleAuthModel;
import com.snake.springboot.custom.api.request.base.CustRoleAuthReq;
import com.snake.springboot.custom.api.service.base.CustRoleAuthService;
import com.snake.springboot.custom.dao.mybatis.entity.base.CustRoleAuthDO;
import com.snake.springboot.custom.dao.mybatis.mappers.base.CustRoleAuthMapper;
import com.snake.springboot.custom.service.assemble.base.CustRoleAuthAssemble;
import org.snake.common.utils.ListUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 商户角色权限实现类Service
 * 类{@code CustRoleAuthServiceImpl} </br>
 * 创建时间 2025/02/08 09:36
 * @author yangxt
 * @see
 */
@Service
public class CustRoleAuthServiceImpl implements CustRoleAuthService{

    @Autowired
    private CustRoleAuthMapper custRoleAuthMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public CustRoleAuthReq addCustRoleAuth(CustRoleAuthReq req) {
        custRoleAuthMapper.del(req.getCustRoleId());
        List<CustRoleAuthDO> authDOS = CustRoleAuthAssemble.roleAuthDOListAss(req);
        if (ListUtils.isEmpty(authDOS)){
            return null;
        }
        custRoleAuthMapper.batchInsert(authDOS);
        return req;
    }

    @Override
    public List<CustRoleAuthModel> queryCustRoleAuthList(CustRoleAuthModel model) {
        CustRoleAuthDO queryDO=CustRoleAuthAssemble.roleAuthDO(model);
        List<CustRoleAuthDO> dos = custRoleAuthMapper.queryList(queryDO);
        List<CustRoleAuthModel> models = ListUtils.copy(dos, CustRoleAuthModel.class);
        return models;
    }
}
